from ferris import Controller, scaffold
from ferris.components.pagination import Pagination
from app.models.issue import Issue
from app.models.column import Column
from app.models.artist import Artist
from app.models.publication import Publication
from app.models.period import Period


class Features(Controller):
    class Meta:
        components = (scaffold.Scaffolding, Pagination)
        pagination_limit = 25

    def list(self):
        if 'query' in self.request.params:
            query = self.request.params['query']
            self.context['search_query'] = query
        else:
            query = None

        self.context['features'] = self.meta.Model.list_query(query)

    def view(self, key):
        item = self.util.decode_key(key).get()
        if not item:
            return 404

        self.context['feature'] = item

        issue = item.issue.get()
        if issue and issue.cover_image_link:
            self.context['media'] = {'link': issue.cover_image_link,
                                     'height': '200',
                                     'alt': 'issue cover'}
    add = scaffold.add
    edit = scaffold.edit
    delete = scaffold.delete

    def home(self):
        pass
